home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 37 / IOPROG_37.ISO / SOFT / Multilizer.exe / disk1 / data1.cab / data1 / [Group9]VCL Source Standard / ivodbcreg.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-08-12  |  3.9 KB  |  173 lines

  1. // This unit registers the ODBC dictionary component of Multilizer.
  2. //
  3. // Copyrights 1995-1998 Innoview Data Technologies Oy
  4.  
  5. unit IvODBCReg;
  6.  
  7. {$I IVMULTI.INC}
  8.  
  9. interface
  10.  
  11. procedure Register;
  12.  
  13. implementation
  14.  
  15. uses
  16.   Windows, Classes, Controls, DsgnIntf, SysUtils,
  17. {$IFNDEF VER93}
  18.   ODBC, IvODBCDic, IvConnection, IvPassWD;
  19. {$ENDIF}
  20.  
  21. {$IFNDEF VER93}
  22.  
  23. // TIvODBCTableNameProperty
  24.  
  25. type
  26.   TIvODBCTableNameProperty = class(TStringProperty)
  27.   public
  28.     function GetAttributes: TPropertyAttributes; override;
  29.     procedure GetValues(Proc: TGetStrProc); override;
  30.   end;
  31.  
  32. var
  33.   connection: TIvConnection;
  34.  
  35. function TIvODBCTableNameProperty.GetAttributes: TPropertyAttributes;
  36. begin
  37.   Result := [paMultiSelect, paValueList, paSortList, paRevertable];
  38. end;
  39.  
  40. procedure TIvODBCTableNameProperty.GetValues(Proc: TGetStrProc);
  41. var
  42.   dialog: TIvPasswordDialog;
  43.   resultSet: TIvResultSet;
  44.   dictionary: TIvODBCDictionary;
  45. begin
  46.   dictionary := GetComponent(0) as TIvODBCDictionary;
  47.  
  48.   // If the data source has changed since last connect, closes the connection
  49.  
  50.   if dictionary.DataSource <> connection.DataSource then
  51.     connection.Close;
  52.   connection.DataSource := dictionary.DataSource;
  53.  
  54.   // Connects to the database
  55.  
  56.   while True do
  57.   begin
  58.     // If the connection is not active and the user name/password was not given
  59.     // ask them.
  60.  
  61.     if (not connection.Active) and
  62.       ((dictionary.UserName = '') or (dictionary.Password = '')) then
  63.     begin
  64.       // No user id given. Asks one
  65.  
  66.       dialog := TIvPasswordDialog.Create(nil);
  67.       try
  68.         dialog.UserName.Text := dictionary.UserName;
  69.         dialog.Password.Text := dictionary.Password;
  70.         if dialog.ShowModal = mrOK then
  71.         begin
  72.           connection.UserName := dialog.UserName.Text;
  73.           connection.Password := dialog.Password.Text;
  74.         end
  75.         else
  76.           Exit;
  77.       finally
  78.         dialog.Free;
  79.       end;
  80.     end;
  81.  
  82.     resultSet := nil;
  83.     try
  84.       connection.Open;
  85.  
  86.       resultSet := connection.SelectTables;
  87.       while resultSet.Next do
  88.       begin
  89.         if CompareText(resultSet.Columns[3].AsString, 'TABLE') = 0 then
  90.           Proc(resultSet.Columns[2].AsString);
  91.       end;
  92.       resultSet.Free;
  93.       Break;
  94.     except
  95.       resultSet.Free;
  96.       connection.Close;
  97.       dictionary.UserName := '';
  98.       dictionary.Password := '';
  99.       raise;
  100.     end;
  101.   end;
  102. end;
  103.  
  104. // TIvDataSourceProperty
  105.  
  106. type
  107.   TIvDataSourceProperty = class(TStringProperty)
  108.   public
  109.     function GetAttributes: TPropertyAttributes; override;
  110.     procedure GetValues(Proc: TGetStrProc); override;
  111.   end;
  112.  
  113. function TIvDataSourceProperty.GetAttributes: TPropertyAttributes;
  114. begin
  115.   Result := [paMultiSelect, paValueList, paSortList, paRevertable];
  116. end;
  117.  
  118. procedure TIvDataSourceProperty.GetValues(Proc: TGetStrProc);
  119. var
  120.   i: Integer;
  121. begin
  122.   for i := 0 to IvEnvironment.DataSourceCount - 1 do
  123.     Proc(IvEnvironment.DataSources[i].ServerName);
  124. end;
  125. {$ENDIF}
  126.  
  127. procedure Register;
  128. begin
  129. {$IFNDEF VER93}
  130.   // ODBC dictionary
  131.  
  132.   if not IsODBCAvailable then
  133.     Exit;
  134.  
  135.   RegisterComponents('Multilizer', [TIvODBCDictionary]);
  136.  
  137.   RegisterPropertyEditor(
  138.     TypeInfo(String),
  139.     TIvODBCDictionary,
  140.     'TableName',
  141.     TIvODBCTableNameProperty);
  142.  
  143.   RegisterPropertyEditor(
  144.     TypeInfo(String),
  145.     TIvODBCDictionary,
  146.     'LanguageTableName',
  147.     TIvODBCTableNameProperty);
  148.  
  149.   RegisterPropertyEditor(
  150.     TypeInfo(String),
  151.     TIvODBCDictionary,
  152.     'LocaleTableName',
  153.     TIvODBCTableNameProperty);
  154.  
  155.   RegisterPropertyEditor(
  156.     TypeInfo(String),
  157.     TIvODBCDictionary,
  158.     'DataSource',
  159.     TIvDataSourceProperty);
  160. {$ENDIF}
  161. end;
  162.  
  163. {$IFNDEF VER93}
  164. initialization
  165.   if IsODBCAvailable then
  166.     connection := TIvConnection.Create
  167.   else
  168.     connection := nil;
  169. finalization
  170.   connection.Free;
  171. {$ENDIF}
  172. end.
  173.